{extend name="base" /}
{block name="title"}
<title>系统配置管理-修改</title>
{/block}
{block name="content"}

<fieldset class="layui-elem-field layui-field-title">
    <legend>
        <span class="layui-breadcrumb">
            <a href="{:url('admin/config/index')}">系统配置管理</a>
            <a><cite>修改</cite></a>
        </span>
    </legend>
    <br>
    <!--<a href="{:url('admin/config/add')}" class="layui-btn" target="">添加配置</a>-->
    <a href="{:url('admin/config/index')}" class="layui-btn layui-btn-normal" target="">配置列表</a>
</fieldset>
<!--<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>方框风格的表单集合</legend>
</fieldset>-->

<form class="layui-form layui-form-pane" action="" method="post">
    <table class="layui-table">
        <colayui-inputroup>
            <col width="10%">
            <col width="80%">
        </colayui-inputroup>
        <thead>
        <tr>
            <th class="tc">名称</th>
            <th class="tc">值</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <th><i class="require">*</i>配置中文名称：</th>
            <td>
                <input type="text" value="{$data->zh_name}" name="zh_name" lay-verify="require" placeholder="请输入" autocomplete="off" class="layui-input">
                <span></span>
            </td>
        </tr>

        <tr>
            <th><i class="require">*</i>类型：</th>
            <td>
                {if $data.field_type == 'img'}
                <div class="site-demo-upload">
                    <img id="LAY_demo_upload" src="{$data.content}" width="553px" height="113px">
                    <div class="site-demo-upbar">
                        <input type="file" name="file" class="layui-upload-file" id="test">
                    </div>
                </div>
                <input id="content1" class="layui-input" type="hidden" name="content" value="{$data.content}">
                {else}
                <select name="field_type" id="select_type1" onchange="showTr()">
                    <option value="input" {if  $data.field_type == 'input'}selected{/if}>input</option>
                    <option value="textarea" {if  $data.field_type == 'textarea'}selected{/if}>textarea</option>
                </select>
                {/if}
            </td>
        </tr>
        <tr id="content">
            <th><i class="require"></i>内容</th>
            <td>
                <input type="text" value="{$data.field_value}" name="field_value" lay-verify="" placeholder="请输入" autocomplete="off" class="layui-input">
            </td>
        </tr>
        <tr>
            <th><i class="require"></i>描述</th>
            <td>
                <textarea placeholder="请输入内容" name="tips" class="layui-textarea">{$data.tips}</textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div class="layui-form-item">
                    <input type="hidden" name="id" value="{$data.id}">
                    <!--<button class="layui-btn" lay-submit="" lay-filter="sub">提交</button>-->
                    <input type="submit" class="layui-btn" value="提交">
                </div>
            </td>
        </tr>
        </tbody>
    </table>
</form>
{/block}
{block name="js"}
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.min.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layedit', 'laydate','element','upload'], function () {
        var form = layui.form(), layer = layui.layer, layedit = layui.layedit, laydate = layui.laydate,element = layui.element;

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value.length < 2) {
                    return '标题至少得2个字符啊';
                }
            }
            , pass: [/(.+){6,12}$/, '密码必须6到12位']
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(sub)', function (data) {
            /*layer.alert(JSON.stringify(data.field), {
             title: '最终的提交信息'
             });*/
            return true;
        });

        layui.upload({
            url: '{:url("/admin/common/upload/type/config")}'
            ,elem: '#test' //指定原始元素，默认直接查找class="layui-upload-file"
            ,method: 'post' //上传接口的http类型
            ,success: function(datap){
                //var datap = JSON.parse(data); //$.parseJSON(data);
                layer.msg(datap.msg);
                if(datap.errno == 0) {
                    /*$("input[name='img_url']").val(datap.path);
                     $('#img_url_img').attr('src', datap.path);*/
                    LAY_demo_upload.src = datap.path;
                    content1.value = datap.path;
                }
            }
        });
    });

    showTr();
    function showTr() {
        var type = $('#select_type').val();
        if(type == 'radio') {
            $('#content').show();
        }else {
            $('#content').hide();
        }
    }
</script>
{/block}